package com.tueye.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;

import com.tueye.annotation.GridFieldConfig;
import com.tueye.annotation.ModifyType;

/**
 * 统一定义id的entity基类,所有实体需要继承此类
 * @author hanxiaowei
 *
 */
@SuppressWarnings("serial")
@MappedSuperclass
public class BaseEntity  implements Serializable {
	
	@GridFieldConfig(modifytype=ModifyType.text,showName="主键",size=50,sortable=true)
	private String id;
	@GridFieldConfig(modifytype=ModifyType.text,showName="填写时间",size=50,sortable=true)
	private Date sys_time;//填写时间
	@GridFieldConfig(modifytype=ModifyType.text,showName="填写人",size=50,sortable=true)
	private String sys_fille;//填写人
	
	@Id
	@Column(name="id", length = 40)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "sys_time", length = 7)
	public Date getSys_time() {
		return sys_time;
	}

	public void setSys_time(Date sys_time) {
		this.sys_time = sys_time;
	}
	 @Column(name = "sys_fille", length = 40)
	 public String getSys_fille() {
		return sys_fille;
	}

	public void setSys_fille(String sys_fille) {
		this.sys_fille = sys_fille;
	}

	// add by  yue . 2008/12/21 you can see the folds doc.
	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		
		if(this == obj) return true;
		
		if(!(obj  instanceof BaseEntity))
			 return false;
		// if not through Above ,will throw excption of  ClassCaseException
		BaseEntity entiry = (BaseEntity)obj;
		
		if(this.getId() != null && this.getId().length()>0 ){
			return this.getId().equals(entiry.getId());
		}
		 // if don't execute Above,that this.id is null or.. so if enrity.getId != null will 
		 //  return false
		if(entiry.getId() != null && entiry.getId().length()>0 ){
			return false;
		}
		//about EqualsBuilder you can see the doc..
		return EqualsBuilder.reflectionEquals(this, entiry);
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		if(this.getId() != null && this.getId().length()>0){
			return this.getId().hashCode();
		}
		return HashCodeBuilder.reflectionHashCode(this);
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		 return ReflectionToStringBuilder.toString(this);
	}
	
	
}
